<template>
	<view>
		<view class="list w-1 fr-b-s p-r-30">
			<view class="list-item fl-s-s" v-for="(item,index) in list" :key="index" @click="toDetail(item.id,item.platform,item.c_father_goods_id)">
				<image :src="item.image" mode="aspectFill" style="width: 332rpx; height: 282rpx;"></image>
				<view class="fr-s-c w-1 relative" style="height: 32rpx; padding-left: 20rpx; margin-top: -18rpx;">
					<view class="fr-c label" v-if="item.is_new==1">新品</view>
					<view class="fr-c label" v-if="item.type_i==1">推荐</view>
				</view>
				<text class="m-t-10 w-1 text-line-2 c-00 fs-30 fm-ali" style="height: 83rpx; padding: 0 20rpx;">{{item.title}}</text>
				<view class="fr-s-c fm-ali" style="padding-left: 20rpx; color: #FA360A; align-items: baseline;">
					<text class="fs-24">￥</text>
					<text class="fs-36">{{item.price | pointsPrice}}</text>
					<text class="fs-20">.{{item.price | pointsPrice(1)}}</text>
				</view>
			</view>
		</view>
		<view class="m-t-250" v-if="nodata">
			<u-empty mode="data"></u-empty>
		</view>
	</view>
</template>

<script>
	import {pointsPrice} from '@/utils/util.js'
	export default {
		data() {
			return {
				src:'',
				list:[],
				nodata:false
			}
		},
		async onLoad(e) {
			this.src = decodeURIComponent(e.src)
			console.log(this.src)
			const imgres = await this.$up({
				imageUrl:[...[this.src]]
			})
			this.src = imgres[0]
			console.log('this.src:',this.src);
			this.getList()
		},
		filters:{
			pointsPrice
		},
		methods: {
			getList(){
				this.$post({
					url:'/wanlshop/product/imageSearch',
					data:{
						img:this.src
					}
				}).then(res=>{
					this.list = res.data
					this.nodata = !this.list.length
				}).catch(err=>{
					this.list = []
					this.nodata = !this.list.length
				})
			},
			// 去商品详情
			toDetail(id,platform,c_father_goods_id) {
				let c_father = c_father_goods_id || 0
				if(!uni.getStorageSync('user_id')){
					uni.navigateTo({
						url:"/pages/Login/Login"
					})
					return
				}
				uni.navigateTo({
					url: '/pages/Home/GoodsDetail/GoodsDetail?id=' + id+'&platform='+platform+'&c_father_goods_id='+c_father
				})
			},
		}
	}
</script>

<style>
.list {
		padding-top: 20rpx;
		flex-wrap: wrap;
	}

	.list-item {
		width: 332rpx;
		height: 450rpx;
		background: #FDFBFB;
		border-radius: 16rpx;
		margin-bottom: 20rpx;
		overflow: hidden;
	}

	.label {
		height: 32rpx;
		background: linear-gradient(270deg, #EBC66D 0%, #EFDDB2 100%);
		border-radius: 4rpx;
		font-size: 20rpx;
		font-family: Alibaba;
		color: #FFFFFF;
		padding: 0 20rpx;
		margin-right: 8rpx;
	}
</style>
